//
//  HJBaseTabBarController.swift
//  HJSinaWeibo
//
//  Created by 夏航军 on 17/9/3.
//  Copyright © 2017年 夏航军. All rights reserved.
//

import UIKit

class HJBaseTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBar = HJBaseTabBar()
        self.setValue(tabBar, forKeyPath: "tabBar");
        //闭包
        tabBar.composeClosure = {
            print("点击杜撰按钮");
        }
        
        self.addChildViewControllers();
    }
    
    func addChildViewControllers() {
        self.setChildViewController(vc: HJHomeTableViewController(), title: "首页", imageName: "tabbar_home", selectImage: "tabbar_home_selected");
        self.setChildViewController(vc: HJMessageTableViewController(), title: "消息", imageName: "tabbar_message_center", selectImage: "tabbar_message_center_selected");
        self.setChildViewController(vc: HJDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover", selectImage: "tabbar_discover_selected");
        self.setChildViewController(vc: HJUserCenterTableViewController(), title: "我", imageName: "tabbar_profile", selectImage: "tabbar_profile_selected");
    }
    
    
    func setChildViewController(vc : UIViewController,title : String,imageName : String,selectImage : String) {
        vc.navigationItem.title = title;
        vc.tabBarItem.title = title;
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected);
        vc.tabBarItem.image = UIImage(named: imageName);
        vc.tabBarItem.selectedImage = UIImage(named: selectImage)?.withRenderingMode(UIImageRenderingMode.alwaysOriginal);
        
        
        let nav = UINavigationController(rootViewController: vc);
        self.addChildViewController(nav);
        
    }


}
